import { getToken, request } from '@inbiz/utils';

// 获取流程按钮权限
export async function getPermissions(params?: any) {
  const token = getToken();
  return request(
    `/edoc2Flow-web/edoc-task/${params.taskId}/getActivityInfo?taskId=${params.taskId}&orgToken=${token}`,
    {
      method: 'get',
      headers: {
        vVersion: 'v6',
      },
    },
  );
}

/*
发起申请
'processDefinitionId':'', 流程解析KEY
'starter':'', 发起人ID
'variablesParams ': [{"name":"num","value":"2"}],
'signDataStr':'', 电子签名
'businessKey':''  表单提交id
*/
export async function startProcess(params?: any) {
  return request(`/edoc2Flow-web/process/operation/initiatingProcess`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 退回
export async function sendBack(params?: any) {
  return request(`/edoc2Flow-web/process/operation/processReturn`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/*
终止流程
id: '' 流程实例号 
taskId: '' 任务ID
comment: '' 审批意见 
*/
export async function cancelProcess(params?: any) {
  return request(`/edoc2Flow-web/process/operation/processStop`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/*
保存到草稿箱
starer: '' 发起人ID
procDefId: '' 流程定义ID，实例：’process9963a6a6ebf246c7a4bbfb9e4ff7e792:1:15004‘
*/
export async function saveDraft(params?: any) {
  return request(`/edoc2Flow-web/process/operation/saveDraft`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/*
加签
taskId: '' 任务ID
plusSignType: '' skipCurrent：前加签；skipNext:后加签
commonet: '' 审批意见
assigenLists: '' 被加签人ID（多人使用逗号隔开）
*/
export async function plusSign(params?: any) {
  return request(`/edoc2Flow-web/process/operation/processSignature`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/**
 * 同意
 *  taskId
 * comment
 *  variablesParams
 */

export async function approval(params?: any) {
  return request(`/edoc2Flow-web/process/operation/processCompletion`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 获取变量信息
export async function getVariables(params) {
  const token = getToken();
  return request(`/edoc2Flow-web/edoc-etc-processManage/getMobileVars?orgToken=${token}`, {
    method: 'get',
    params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 撤回
export async function withDrawProcess(params?: any) {
  return request(`/edoc2Flow-web/process/operation/Withdrawal`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 抄送
export async function sendTo(params?: any) {
  return request(`/edoc2Flow-web/process/operation/processSendCC`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 退回后的提交
export async function submitTask(params?: any) {
  return request(`/edoc2Flow-web/process/operation/processCompletion`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 催办
export async function doItFast(params?: any) {
  return request(`/edoc2Flow-web/process/operation/processUrging`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 删除发起失败的数据
export async function removeData(params?: any) {
  return request(`/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/business/data`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 删除草稿
export async function delDepositDraft(params: { drafID: string }) {
  return request(`/edoc2Flow-web/process/operation/delDepositDraft`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 获取流程状态
export async function getTaskState(taskId: string) {
  return request(`/edoc2Flow-web/edoc-task/getTaskState?taskId=${taskId}`, {
    method: 'get',
    headers: {
      vVersion: 'v6',
    },
  });
}

// 删除抄送信息
export async function deleteSended(params?: any) {
  return request(`/edoc2Flow-web/process/operation/deleteProcessCC`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 指派
export async function assignTask(params: any) {
  return request(`/edoc2Flow-web/process/operation/processAssignment`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}